package com.cci.kangdao.service.impl;

import com.cci.kangdao.dao.CommonQuestionTDao;
import com.cci.kangdao.service.CommonQuestionTService;
import com.cci.kangdao.utilTool.ParameterTool;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;


//常见问题接口实现类
@Service("CommonQuestionTService")
public class CommonQuestionTServiceImpl implements CommonQuestionTService {

	private Logger log = Logger.getLogger(this.getClass().getName());
	
	@Autowired
	private CommonQuestionTDao commonQuestionTDao;
	
	//获取所有常见问题种类
	@Transactional
	@Override
	public ModelAndView getCommonQuestionTypeList(Map<String, Object> map) {
		HttpServletResponse response = (HttpServletResponse)map.get("response");
		HttpServletRequest request = (HttpServletRequest)map.get("request");
		JSONObject obj = new JSONObject();   //保存返给手机端的数据容器
		List<Map<String, Object>> commonQuestionTypeList = commonQuestionTDao.getCommonQuestionTypeList();  //根据服务站id获取服务渠道
		obj.put("status", 0);
		obj.put("msg", "查询成功");
		obj.put("data", commonQuestionTypeList);
		ParameterTool.writeResponse(response, obj.toString());	
		return null;
	}


	//根据常见问题分类获取常见问题详情集合
	@Transactional
	@Override
	public ModelAndView getCommonQuestionDetailList(Map<String, Object> map) {
		HttpServletResponse response = (HttpServletResponse)map.get("response");
		HttpServletRequest request = (HttpServletRequest)map.get("request");
		long commonQuestionTypeID = Long.parseLong(map.get("commonQuestionTypeID").toString());
		JSONObject obj = new JSONObject();   //保存返给手机端的数据容器
		int pageNo = 1;
		int pageSize = 20;
		if(null != map.get("pageNo")){
			pageNo = Integer.parseInt(map.get("pageNo").toString());
		}
		if(null != map.get("pageSize")){
			pageSize = Integer.parseInt(map.get("pageSize").toString());
		}
		PageHelper.startPage(pageNo,pageSize);
		List<Map<String, Object>> commonQuestionDetailList = commonQuestionTDao.getCommonQuestionDetailList(commonQuestionTypeID);
		PageInfo pageInfo = new PageInfo(commonQuestionDetailList);
		obj.put("status", 0);
		obj.put("msg", "查询成功");
		obj.put("data", pageInfo);
		ParameterTool.writeResponse(response, obj.toString());
		return null;
	}
}
